mitmproxy 抓包
mitmproxy 官网
https://www.mitmproxy.org/#mitmproxy
证书
http://mitm.it/
启动命令
mitmdump -k -p 9009
mitmdump --mode socks5
mitmdump -k -p 9009 > /opt/soft/v2/mitm.log
journalctl -u nginx.service
journalctl -fxeu nginx.service
证书安装
magisk 证书包
http://mitm.it/cert/magisk
手动安装
第一步,先下载好Fiddler或Mitmproxy的证书文件,PEM或者DER格式均可。
第二步,获取有效的系统证书文件名。
# 如果是PEM格式的:
openssl x509 -inform PEM -subject_hash_old -in mitmproxy-ca-cert.pem -noout
# 如果是DER格式的:
openssl x509 -inform der -subject_hash_old -in FiddlerRoot.cer -noout
# 例如,输出8bbe0e8d
# 第三步,转换证书格式为PEM格式,并重命名证书为有效的系统证书名。
# 如果是PEM格式 的:
openssl x509 -inform PEM -in mitmproxy-ca-cert.pem -out 8bbe0e8d.0
# 如果是DER格式的:
openssl x509 -inform der -in FiddlerRoot.cer -out 8bbe0e8d.0
复制证书到Android系统证书目录
cp /sdcard/8bbe0e8d.0 /system/etc/security/cacerts
修改证书权限
chmod644 /system/etc/security/cacerts/8bbe0e8d.0
#encoding=utf-8
import mitmproxy.http
from mitmproxy import ctx
import logging
class Demo:
def request(self, flow: mitmproxy.http.HTTPFlow):
request_demo=flow.request
self.url=request_demo.url
self.req_headers=request_demo.headers
self.htype=request_demo.method
f_handler = logging.FileHandler('error.log')
f_handler.setLevel(logging.INFO)
f_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
logger = logging.getLogger('mylogger')
logger.addHandler(f_handler)
logger.info('url: {}'.format(self.url))
def response (self, flow: mitmproxy.http.HTTPFlow) :
response_demo = flow.response
code = response_demo.status_code
res_headers=response_demo.headers
res_text=response_demo.get_text()
# ctx.log.info('url: {}'.format(self.url))
#ctx.log.info('Headers: {}'.format(res_headers))
#ctx.log.info('Text: {}'.format(res_text))
# response_demo.set_text('sucess')
# ctx.log.info('====================================')
f_handler = logging.FileHandler('error.log')
f_handler.setLevel(logging.INFO)
f_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))
logger = logging.getLogger('mylogger')
logger.addHandler(f_handler)
logger.info('{} url: {} code: {}'.format(self.htype,self.url,code))
addons = [
Demo()
]
vim /usr/lib/systemd/system/mitm.service
[Unit]
Description=mitm client
After=network.target
Wants=network.target
[Service]
#Type=simple
#EnvironmentFile=
Restart=on-failure
RestartSec=5
WorkingDirectory=/opt/soft/
#启动服务的命令(此处写你的frps的实际安装目录 客户端or服务端)
ExecStart=/opt/soft/mitmdump -k -p 9009 -s /opt/soft/sock.py
[Install]
WantedBy=multi-user.target